package ccm.itesm.mx.servicios;

import java.io.IOException;
import java.util.ArrayList;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class Prototipo1Activity extends Activity {
    /** Called when the activity is first created. */
	private Button b;
	ProgressDialog progresa;
	private ArrayList<String> nombreProfesores;
	private ArrayList<String> claveMaterias;
	private ArrayList<String> nombreMaterias;
		@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.main2);
        b =(Button)findViewById(R.id.button1);
        final EditText var =(EditText)this.findViewById(R.id.editText1);
        
        b.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub

				String matricula = var.getText().toString();
				Bundle bundle = new Bundle();
				bundle.putString("matricula", matricula);
				progresa = ProgressDialog.show(Prototipo1Activity.this,"Procesando....","Recuperando Datos...",true,false);
				localizaMetodo(matricula);
				
				
				Intent intento  = new Intent (getApplicationContext(),CalificacionesList.class);
				intento.putExtras(bundle);
				startActivityForResult(intento, 0);
    }
        });
	}
		
		public void localizaMetodo(final String localiza){
			Thread t = new Thread(){
				public void run(){
					
						nombreMaterias = getMaterias(localiza); 
						unHandler.sendEmptyMessage(0); 
						
					
				}
			};
			t.start();
			
		}
		
		private Handler unHandler = new Handler(){
			public void handleMessage(Message ms){
				progresa.dismiss();
				if(nombreMaterias!=null && nombreMaterias.size()>0) {
				
				}else{
					Dialog noHayResultados = 
						new AlertDialog.Builder(Prototipo1Activity.this)
					.setIcon(0).setTitle("No hay")
					.setPositiveButton("OK", null)
					.setMessage("SIN RESULTADOS").create();
					
					noHayResultados.show();
				}
			
			}
		};
	

		public ArrayList<String>getMaterias(String localiza){
			return nombreMaterias;
		}
		
}
        
